package alg.picGui;

import java.awt.BorderLayout;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Die graphische Oberfläche wird hier aufgebaut
 * 
 * @author Patrick Englert
 *
 */
@SuppressWarnings("serial")
public class PicGUI extends JPanel implements ChangeListener {
	
	private static JFrame frame;
	private static Pictures labels;
	private static JSlider slider;
	boolean loaded = false;
	
	public PicGUI() {
		super(new BorderLayout()); 
			Buttons buttons;
			labels = new Pictures(this);
			buttons = new Buttons(labels);
			
			slider = new JSlider(0, 160, 50);
			slider.addChangeListener(this);
			
			slider.setMajorTickSpacing(20);
			slider.setMinorTickSpacing(10);
			slider.setPaintLabels(true);
			slider.setPaintTicks(true);
			
			slider.setName("Toleranz");
			slider.setToolTipText("Toleranz");
			
			add(labels,BorderLayout.NORTH);
			add(buttons,BorderLayout.WEST);
			add(slider,BorderLayout.EAST);
	}
	
	public void stateChanged(ChangeEvent e) {
		if (loaded) {
			JSlider source = (JSlider) e.getSource();
			labels.setDiff(source.getValue());
			labels.doChanges();
		}
	}
	
	public void pack() {
		frame.pack();
		frame.setVisible(true);
	}

    /**
     * frame wird angelegt 
     * danach die weiteren labels und buttons
     */
    public static void createAndShowGUI() {
        //Create and set up the window.
        frame = new JFrame("PicGUI");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocation(200, 200);
        //Add content to the window.
        frame.add(new PicGUI());
 
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }
}

